package mainFragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.ArrayList;

import mainFragment.bean.VolunteerListBean;
import view.MyImageLoader;

/**
 * Created by Administrator on 2017/6/13.
 */

public class CollegeIndexVolunteerListAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<VolunteerListBean.VolunteerListbean> arrayList;
    private int blue;
    private int orange;

    public CollegeIndexVolunteerListAdapter(Context context, ArrayList<VolunteerListBean.VolunteerListbean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
        blue = context.getResources().getColor(R.color.common_color);
        orange = context.getResources().getColor(R.color.orange);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
        if (convertView == null) {
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.oa_expandable_lv_child_item, null);
            myHolder.oa_listView_item_icon = (RoundedImageView) convertView.findViewById(R.id.oa_listView_item_icon);
            myHolder.oa_listView_item_vip_ima = (ImageView) convertView.findViewById(R.id.oa_listView_item_vip_ima);
            myHolder.oa_listView_item_name = (TextView) convertView.findViewById(R.id.oa_listView_item_name);
            myHolder.oa_listView_item_more = (TextView) convertView.findViewById(R.id.oa_listView_item_more);
            myHolder.oa_listView_item_title = (TextView) convertView.findViewById(R.id.oa_listView_item_title);
            myHolder.oa_listView_item_ask = (TextView) convertView.findViewById(R.id.oa_listView_item_ask);
            convertView.setTag(myHolder);
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        myHolder.oa_listView_item_name.setText(arrayList.get(position).getName());
        MyImageLoader.showImage(arrayList.get(position).getImage(), myHolder.oa_listView_item_icon);
        myHolder.oa_listView_item_more.setText(arrayList.get(position).getMajor());

        switch (arrayList.get(position).getType()) {
            case "vip":
                myHolder.oa_listView_item_ask.setText("立即提问");
                if (arrayList.get(position).getBrief() != null) {
                    myHolder.oa_listView_item_title.setText(arrayList.get(position).getBrief());
                }
                myHolder.oa_listView_item_ask.setTextColor(blue);
                myHolder.oa_listView_item_ask.setBackgroundResource(R.drawable.shape_corner);
                myHolder.oa_listView_item_vip_ima.setVisibility(View.GONE);
                break;
            case "official":
                myHolder.oa_listView_item_ask.setText("免费提问");
                myHolder.oa_listView_item_title.setText("官方咨询员");
                myHolder.oa_listView_item_ask.setTextColor(orange);
                myHolder.oa_listView_item_ask.setBackgroundResource(R.drawable.shape_corner_orange);
                myHolder.oa_listView_item_vip_ima.setVisibility(View.VISIBLE);
                break;
            case "normal":
            default:
                myHolder.oa_listView_item_ask.setText("免费提问");
                if (arrayList.get(position).getGrade() != null) {
                    myHolder.oa_listView_item_title.setText(arrayList.get(position).getGrade());
                }
                myHolder.oa_listView_item_ask.setTextColor(orange);
                myHolder.oa_listView_item_ask.setBackgroundResource(R.drawable.shape_corner_orange);
                myHolder.oa_listView_item_vip_ima.setVisibility(View.GONE);
                break;
        }
        return convertView;
    }

    class MyHolder {
        RoundedImageView oa_listView_item_icon;
        ImageView oa_listView_item_vip_ima;
        TextView oa_listView_item_name;
        TextView oa_listView_item_more;
        TextView oa_listView_item_title;
        TextView oa_listView_item_ask;
    }

}
